<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../plugins/layui/css/style.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../layuiadmin/style/admin.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../plugins/zTree/css/metroStyle/metroStyle.css?v=${.Config.basic.version}">
    <link rel="stylesheet" href="../plugins/zTree/css/metroStyle/ext.css?v=${.Config.basic.version}">
    <link rel="stylesheet" href="//at.alicdn.com/t/c/font_3564966_a6tt4yhnzge.css" media="all">
    <link rel="stylesheet" href="../plugins/toastr/toastr.min.css?v=${.Config.basic.version}">
    <style>

        .layui-form-item .layui-input-inline {
            float: left;
            width: 150px;
            margin-right: 10px;
        }
        .layui-form-item {
            margin-top: 5px;
            margin-bottom: 10px;
        }

        .layui-btn + .layui-btn {
            margin-left: 5px;
        }
        .layui-btn-xs {
            height: 18px;
            line-height: 18px;
            padding: 0 5px;
            font-size: 11px;
        }

        .layui-form-label-lg {
            float: left;
            display: block;
            padding: 9px 15px;
            width: 130px;
            font-weight: 400;
            line-height: 20px;
            text-align: right;
        }

        /*.layui-form-item .layui-input[readonly] {*/
        /*    background-color: #0a1434;*/
        /*    color: #a6b8d5;*/
        /*    border: none;*/
        /*    border-top-color: currentcolor;*/
        /*    border-right-color: currentcolor;*/
        /*    border-bottom-color: currentcolor;*/
        /*    border-left-color: currentcolor;*/
        /*}*/
        .layui-form-pane .layui-form-label {
            width: 110px;
            padding: 8px 15px;
            padding-top: 8px;
            padding-right: 15px;
            padding-bottom: 8px;
            padding-left: 15px;
            height: 34px;
            line-height: 14px;
            border-width: 1px;
            border-style: solid;
            border-radius: 2px 0 0 2px;
            text-align: center;
            background-color: transparent;
            overflow: hidden;
            box-sizing: border-box;
        }
        .layui-form-label-new{
            width: 200px !important;border-color: #6c7492 !important;
        }
        .layui-colla-item {
            border-color: #3c4971;
        }
        .layui-input, .layui-select, .layui-textarea {
            border: 1px solid #6c7492;
        }
        .layui-form-pane .layui-input {
            border-radius: 0;
        }
    </style>
    <!-- <style>
        .layui-table-view .layui-table td, .layui-table-view .layui-table th {
            padding: 5px 0;
            border-top: 1px solid #404453;
            border-left: 1px solid #404453;
            border-bottom: 1px solid #404453;
            border-right: 1px solid #404453;
        }
    </style> -->
</head>
<body class="layui-layout-body">
    <div class="">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" lay-filter="form_search" id="form_search" action="">
                    <div class="layui-form-item">

                        <div class="layui-input-inline" style="width: 150px;">
                            <select name="group_code" lay-filter="group_code" lay-verify="" lay-search="" placeholder="请选择集团">
                                <option value="">请选择集团</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width: 150px;">
                            <select name="farmid" lay-filter="farmid"  lay-verify="" lay-search="" placeholder="请选择场区">
                                <option value="">请选择场区</option>
                            </select>
                        </div>
                        <div class="layui-inline">
                            <!--<label class="layui-form-label auto-size-label"></label>-->
                            <div class="layui-input-inline">
                                
                                <input type="text" name="key" placeholder="请输入关键字" lay-verify="" autocomplete="off" class="layui-input">
                            </div>
                            
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="" lay-filter="btn_search"><i class="layui-icon layui-icon-search"></i>查询</button>
                            <!--<button type="button" class="layui-btn layui-btn-normal layui-btn-sm action-export layui-hide" lay-submit="" lay-filter="btn_search"><i class="fa fa-file-excel-o"></i> 导出</button>-->
                        </div>

                        <div class="layui-inline fr">
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal  action-edit layui-hide" lay-event="add" onclick="onAdd(1);"><i class="layui-icon layui-icon-add-circle"></i> 泌乳方案</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal  action-edit layui-hide" lay-event="add" onclick="onAdd(3);"><i class="layui-icon layui-icon-add-circle"></i> 保育方案</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal  action-edit layui-hide" lay-event="add" onclick="onAdd(4);"><i class="layui-icon layui-icon-add-circle"></i> 育肥方案</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal  action-edit layui-hide" lay-event="add" onclick="onAdd(168);"><i class="layui-icon layui-icon-add-circle"></i> 粥料器方案</button>
                            <!--<button type="button" class="layui-btn layui-btn-normal layui-btn-sm action-export layui-hide" lay-submit="" lay-filter="btn_search"><i class="fa fa-file-excel-o"></i> 导出</button>-->
                        </div>

                    </div>
                </form>

                <!-- <div class="layui-form-item">
                    <div class="fr">
                        
                    </div>
                </div> -->
                

                <table class="layui-hide" id="table" lay-filter="table"></table>
                
            </div>
        </div>
    </div>


    <script src="../plugins/layui/layui.js?v=${.Config.basic.version}"></script>
    <script src="../plugins/layui/xm-select-v1.2.4.js?v=${.Config.basic.version}"></script>
    <script src="../plugins/jquery/jquery-1.10.2.js?v=${.Config.basic.version}"></script>
    <script src="../plugins/zTree/js/jquery.ztree.core.min.js?v=${.Config.basic.version}"></script>
    <script src="../plugins/zTree/js/jquery.ztree.excheck.js?v=${.Config.basic.version}"></script>
    <script src="../plugins/zTree/js/jquery.ztree.exedit.js?v=${.Config.basic.version}"></script>
    <script src="../plugins/jquery.slimscroll.min.js?v=${.Config.basic.version}"></script>
    <script src="../plugins/toastr/toastr.min.js"></script>
    <script src="../js/utils.js?v=${.Config.basic.version}"></script>
    <script src="../js/verify.js?v=${.Config.basic.version}"></script>
    <script src="../js/func.js?v=${.Config.basic.version}"></script>
    <script>
        var table=null;
        var form=null;
        var laydate = null;
        var lay_index=null;
        var Table=null;
        var transfer=null;
        var allData=[];
        var users = [];
        var selectUser = null;
        var copiedItem=null;//复制的方案
        var cur_group_code = null;

        var fieldDictionary={
            "Gday":"日龄",
            "Mode":"模式",

            "CalFeed":"校准",
            "YlCheck":"余料检测",
            "EnWater":"水阀",

            "ManOut":"手动出料",
            "ManWaterOut":"手动出水",
            "FeedWater":"料水比",
            "AutoOut":"单次出料量",
            "Son":"带仔数",
            "Fit":"体况",
        };


        var time_table_para=null;
        var cruve_table_para=null;

        var token = window.localStorage.getItem("token");
        var user_info=JSON.parse(window.localStorage.getItem("user_info"));
        var is_admin = user_info.is_admin;
        if(user_info.role_ids=="service"){
            is_admin = true;
        }
        var func_url="${.func_url}";
        var actions=[];
        var token = window.localStorage.getItem("token");
        token = 'Bearer ' + token;
        layui.config({
            base: '../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index','layer','form', 'table','transfer','laydate'],function(){
            form = layui.form;
            table = layui.table;
            laydate = layui.laydate;
            transfer = layui.transfer;

            toastr.options = {
                "closeButton": false, //是否显示关闭按钮
                "debug": false, //是否使用debug模式
                "positionClass": "toast-top-center",//弹出窗的位置
                "showDuration": "300",//显示的动画时间
                "hideDuration": "1000",//消失的动画时间
                "timeOut": "2000", //展现时间
                "extendedTimeOut": "1000",//加长展示时间
                "showEasing": "swing",//显示时的动画缓冲方式
                "hideEasing": "linear",//消失时的动画缓冲方式
                "showMethod": "fadeIn",//显示时的动画方式
                "hideMethod": "fadeOut" //消失时的动画方式
            };

            $.ajax({
                type: 'GET',
                url: '../Api/User/Actions',
                data: {func_url:func_url},
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                dataType: "json",
                success: function (data) {
                    console.info(data)
                    actions=data.data;
                    for(var i=0;i<actions.length;i++){
                        $('.action-'+actions[i].action_id).removeClass("layui-hide");
                    }
                    //initTable();
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('加载操作信息失败');
                }
            });

            
            form.on('select(group_code)', function(data){
                var group_code=data.value;
                console.info("group_code",group_code);
                renderFarmSelect(group_code);
            });
            

            laydate.render({
                elem: '#StartT'
                ,theme: '#133678'
                ,type: 'time'
                ,format: 'HH:mm'
                ,range: false
                ,ready: formatminutes
            });

            laydate.render({
                elem: '#EndT'
                ,theme: '#133678'
                ,type: 'time'
                ,format: 'HH:mm'
                ,range: false
                ,ready: formatminutes
            });

            $.ajax({
                type: 'GET',
                url: "../Api/User/List",
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                dataType: "json",
                success: function (res) {
                    console.info(res);
                    if(res.code>=0){
                        users=[];
                        var items = res.data;
                        for(var i=0;i<items.length;i++){
                            if(items[i].status>0){
                                var group_name = items[i].group_name?items[i].group_name:"";
                                var area_names = items[i].area_names?items[i].area_names:"";
                                items[i].name_ext = items[i].name+" ("+group_name+area_names+")";
                                users.push(items[i]);
                            }
                        }
                    }else{
                        layer.alert(res.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('加载操作信息失败');
                }
            });



            renderGroupSelect();
            renderFarmSelect();

            initTable();



            //监听提交
            form.on('submit(btn_search)', function(data){
                search(data.field);
                return false;
            });
            //保存分配
            form.on('submit(btn_allocate)', function(data){
                data.field.users = selectUser.getValue('valueStr');
                console.info(data.field);
                //return ;
                layer.load(1);
                $.ajax({
                    type: 'PUT',
                    url: '../Api/FeedPlanNew/Allocate',
                    data: data.field,
                    beforeSend: function(request) {
                        request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                    },
                    success: function(res){
                        if(res){
                            if(res.code>=0){
                                //保存成功
                                toastr.success("保存成功");
                                layui.table.reload('table'); //重载表格
                                layer.close(lay_index); //再执行关闭
                            }else{
                                //layer.alert(res.msg);
                                toastr.warning(res.msg, "异常");
                            }
                        }
                    },
                    complete: function(XMLHttpRequest, textStatus) {
                        layer.closeAll('loading');
                    },
                    dataType: "json"
                });
            });
            //复制保存
            form.on('submit(btn_save_as)', function(data){
                var obj = {};
                obj.name = data.field.name;
                obj.para = copiedItem.para;
                obj.food_plan = copiedItem.food_plan;
                obj.food_type = copiedItem.food_type;
                obj.global = 0;
                //return ;
                layer.load(1);
                $.ajax({
                    type: 'POST',
                    url: '../Api/FeedPlanNew',
                    data: obj,
                    beforeSend: function(request) {
                        request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                    },
                    success: function(res){
                        if(res){
                            if(res.code>=0){
                                //保存成功
                                toastr.success("保存成功");
                                layer.close(lay_index); //再执行关闭
                                layui.table.reload('table'); //重载表格
                            }else{
                                //layer.alert(res.msg);
                                toastr.warning(res.msg, "异常");
                            }
                        }
                    },
                    complete: function(XMLHttpRequest, textStatus) {
                        layer.closeAll('loading');
                    },
                    dataType: "json"
                });
            });
            resize();
        });

        function renderGroupSelect(){
            $.ajax({
                type: 'GET',
                url: '../Api/Group',
                data: {},
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                dataType: "json",
                success: function (res) {
                    console.info(res)
                    if(res.code>=0){
                        var items = res.data;
                        console.info(items)
                        //栏舍下拉
                        var html="<option value='' >请选择集团</option>";
                        for(var i=0;i<items.length;i++){
                            var selectd="";
                            html+="<option "+selectd+" value=\""+items[i].group_code+"\">"+items[i].group_name+"</option>";
                        }
                        $("select[name='group_code']").html(html);
                        form.render('select');
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('加载集团失败');
                }
            });
        }

        function renderFarmSelect(group_code){
            $.ajax({
                type: 'GET',
                url: '../Api/Farm/List',
                data: {},
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                dataType: "json",
                success: function (res) {
                    console.info(res)
                    if(res.code>=0){
                        var items = res.data;
                        console.info(items)
                        //栏舍下拉
                        var html="<option value='' >请选择场区</option>";
                        for(var i=0;i<items.length;i++){
                            var selectd="";
                            if(group_code){
                                if(items[i].group_code==group_code){
                                    html+="<option "+selectd+" value=\""+items[i].id+"\">"+items[i].farmname+"</option>";
                                }
                            }
                            else{
                                html+="<option "+selectd+" value=\""+items[i].id+"\">"+items[i].farmname+"</option>";
                            }
                            
                            
                        }
                        $("select[name='farmid']").html(html);
                        form.render('select');
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('加载集团失败');
                }
            });
        }

        function initTable(){
            Table = table.render({
                elem: '#table'
                //,data:data
                ,url:'../Api/FeedPlanNew/Page'
                ,height: 'full-80'
                ,method:'GET'
                ,headers : {'Authorization': 'Bearer '+window.localStorage.getItem("token")}
                ,where: {plan_use:1}
                ,page: true
                ,limit:30
                //,toolbar: '#table_toolbar' //开启头部工具栏，并为其绑定左侧模板
                ,defaultToolbar: ['']
                ,title: ''
                ,even:true
                ,size: 'sm' //小尺寸的表格
                // ,skin: 'nob' //无框风格
                ,cols: [[
                    //{type: 'checkbox', fixed: 'left'}
                    //{field:'id', title:'ID', width:120, unresize: false, sort: true}
                    /*{field:'', title:'集团/场区',  sort: true, templet: function(d) {
                            var html = "";
                            if(d.global){
                                return "<span lay-event=\"view\" class='layui-text-xs hand layui-text-orange'><i class='layui-text-xs layui-icon layui-icon-diamond'></i>  "+  "系统"+"   </span>";
                            }
                            else{
                                if(d.farmname){
                                    html = d.farmname;
                                }else{
                                    if(d.farmid!==null){
                                        if(d.farmid==0){
                                            html = "集团";
                                        }
                                        else{
                                            html = "未知";
                                        }
                                    }
                                    else{
                                        //html = "待补充设置";
                                        html="<span class='mr-left-md '>待补充设置 <i id='id-tip-"+d.id+"' class='layui-icon layui-icon-tips layui-text-xs  layui-text-orange'></i></span>";
                                    }
                                }
                            }
                            
                            return html;
                        }}*/

                    {field:'group_name', title:'集团',minWidth:110,  sort: true, templet: function(d) {
                        var html = "";
                        if(!d.group_code){
                            return "<span lay-event=\"\" class='layui-text-xs hand layui-text-orange'>待补充 <i class='layui-icon layui-icon-tips'></i> </span>";
                            
                        }else{
                            return "<span lay-event=\"\" class='layui-text-xs hand'>"+  d.group_name+"</span>";
                        }
                        return html;
                    }}
                    ,{field:'farmname', title:'场区',minWidth:130,  sort: true, templet: function(d) {
                        var html = "";
                        if(!d.farmid){
                            return "";
                            
                        }else{
                            return "<span lay-event=\"\" class='layui-text-xs hand'>"+  d.farmname+"</span>";
                        }
                        return html;
                    }}
                    ,{field:'name', title:'名称',minWidth:120,  sort: true, templet: function(d) {
                            var html = "";
                            if(d.global){
                                return "<span lay-event=\"view\" class='layui-text-xs hand layui-text-orange'><i class='layui-text-xs layui-icon layui-icon-diamond'></i>  "+  d.name+"   </span>";
                            }else{
                                return "<span lay-event=\"view\" class='layui-text-xs hand '>"+  d.name+"<i class=''></i> </span>";
                            }
                            return html;
                        }}
                    ,{field:'', title:'类型',width:100, sort: false,align:'center', templet: function(d) {
                        var model = "";
                        if(d.model && d.model=="fg"){
                            model = "<span class='layui-badge-rim'>"+"粥料器 "+"</span>";
                        }else{
                            model = "<span class='layui-badge-rim'>"+"饲喂器 "+"</span>";
                        }
                        return model;
                    }}
                    ,{field:'', title:'方案模式',width:100, sort: false,align:'center', templet: function(d) {
                        var para = JSON.parse(d.para);
                        var mode = "";
                        if(d.model && d.model=="fg"){
                            var mode =(decodeFgMode(para.Mode));
                        }else{
                            var mode =(decodeModeNew(para.Mode));
                        }
                        
                        return mode ;
                    }}
                    ,{field:'', title:'使用中',width:90, sort: false,align:'center', templet: function(d) {
                        return d.plan_use>0?"<i class=\"layui-icon layui-icon-note layui-text-mute \"></i>":"";
                    }}
                    ,{field:'remark', title:'备注', sort: false}
                    

                    // ,{field:'food_type', title:'饲料类型',width:100, sort: true}
                    // ,{field:'food_plan', title:'饲料方案',width:100, sort: true}
                    ,{field:'create_user_name', title:'创建人', width:100, sort: false}
                    ,{field:'create_date', title:'创建时间',width:140,align:'center', sort: true}
                    ,{field:'update_user_name', title:'修改人',width:100, sort: false}
                    ,{field:'update_date', title:'修改时间',width:140,align:'center', sort: true}
                    ,{field:'', title:'操作', width:250,sort: false,align:'left',fixed: 'right', templet: function(d) {
                            var html = "";
                            html += "<a href='#'   class=\"\" lay-event=\"view\"><span class=\"  layui-text-blu\">预览</span></a><span class=\"shortGreyLine\"></span>";
                            
                            
                            if(d.global){
                                html += "<a href='#'   class=\"layui-hide action-edit\" lay-event=\"copy\"><span class=\"  layui-text-blu\">另存为</span></a><span class=\"shortGreyLine layui-hide action-edit\"></span>";
                                if(is_admin){
                                    //管理员才能修改
                                    html += "<a href='#'   class=\"layui-hide action-edit\" lay-event=\"edit\"><span class=\"  layui-text-blu\">修改</span></a><span class=\"shortGreyLine layui-hide action-edit\"></span>";
                                }
                            }else{
                                //非默认方案才可以分配，删除
                                html += "<a href='#'   class=\"layui-hide action-edit\" lay-event=\"copy\"><span class=\"  layui-text-blu\">另存为</span></a><span class=\"shortGreyLine layui-hide action-edit\"></span>";
                                html += "<a href='#'   class=\"layui-hide action-edit\" lay-event=\"edit\"><span class=\"  layui-text-blu\">修改</span></a><span class=\"shortGreyLine layui-hide action-edit\"></span>";
                                html += "<a href='#'   class=\"layui-hide action-allocate\" lay-event=\"allocate\"><span class=\"  layui-text-blu\">分配</span></a><span class=\"shortGreyLine layui-hide action-allocate\"></span>";
                                html += "<a href='#'   class=\"layui-hide action-delete\" lay-event=\"delete\"><span class=\" layui-text-red \">删除</span></a><span class=\"shortGreyLine layui-hide action-delete\"></span>";
                            }
                            
                            return html;
                        }}
                ]]
                ,done: function(res, curr, count){
                    for(var i=0;i<actions.length;i++){
                        $('.action-'+actions[i].action_id).removeClass("layui-hide");
                    }
                    var that = this.elem.next();
                    allData = res.data;
                    var that = this.elem.next();
                    res.data.forEach(function (item, index) {
                        //console.log(item.empName);item表示每列显示的数据
                        // if (index % 2 != 0) {
                        //     var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css("background-color", "#0a1434");
                        // } else {
                        //     var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css("background-color", "#00092b");
                        // }
                    });
                }
            });

            table.on('sort(table)', function(obj){
                table.reload('table', {
                    initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                    ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                        //order_field: obj.field //排序字段
                        //,order_type: obj.type //排序方式
                        order:obj.field+" "+(obj.type||"")
                    }
                });
            });

            table.on('tool(table)', function(obj){
                var data = obj.data;
                switch(obj.event){
                    case 'view':
                        onView(data);
                        break;
                    case 'edit':
                        onEdit(data);
                        break;
                    case 'copy':
                        onCopy(data);
                        break;

                    case 'allocate':
                        onAllocate(data);
                        break;
                    case 'delete':
                        onDelete(data);
                        break;
                };
            });
        }

        function search(params) {
            params.plan_use = 1;
            Table.reload({
                where: params
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        }


        function onAdd(mode) {
            var model = "feed";
            if(mode<160){
                model = "feed";
            }else if(mode==168){
                model = "fg";
                mode = "1";
            }
            var content = "";
            if(model == "fg"){
                content = "../Feed/FgPlanParaEdit?mode="+mode+"&model="+model;
            }else{
                content = "../Feed/FeedPlanParaEdit?mode="+mode+"&model="+model;
            }
            var idx = layer.open({
                area:['95%','85%'],
                type: 2,
                shadeClose: true,
                shade: 0.8,
                title: '新增',
                maxmin: false, //开启最大化最小化按钮
                content: content,
            });
        }

        function onEdit(item) {
            console.info(item);
            var content = "";
            if(item.model == "fg"){
                content = '../Feed/FgPlanParaEdit?id='+item.id+"&model="+item.model;
            }else{
                content = '../Feed/FeedPlanParaEdit?id='+item.id+"&model="+item.model;
            }
            var idx = layer.open({
                area:['95%','85%'],
                type: 2,
                shadeClose: true,
                shade: 0.8,
                title: item.name,
                maxmin: false, //开启最大化最小化按钮
                content: content,
            });
        }

        function onCopy(item) {
            console.info(item);
            copiedItem = item;
            form.val("form_save_as",{name:''});
            layer.open({
                //area: 'auto',
                area:['400px','200px'],
                type: 1,
                shade: 0.3,
                offset: '15%',
                shadeClose:true,
                title: '另存为', //不显示标题
                content: $('#form_save_as'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
                btn: ['确定', '取消']
                ,yes: function(index, layero){
                    lay_index=index;
                    var submit = layero.find("#btn_save_as");
                    submit.click();
                }
            });
        }

        function onView(item) {
            //console.info(item);
            if(item.model == "fg"){
                content = '../Feed/FgPlanParaReadonly?id='+item.id+"&model="+item.model;
            }else{
                content = '../Feed/FeedPlanParaReadonly?id='+item.id+"&model="+item.model;
            }
            var idx = layer.open({
                area:['95%','85%'],
                type: 2,
                shadeClose: true,
                shade: 0.8,
                title: item.name,
                maxmin: false, //开启最大化最小化按钮
                content: content
            });
        }

        function onDelete(item) {
            layer.confirm('确认删除'+item.name+"?", function(index){
                //obj.del();
                layer.load(1);
                $.ajax({
                    type: 'DELETE',
                    url: '../Api/FeedPlanNew',
                    data: item,
                    beforeSend: function(request) {
                        request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                    },
                    dataType: "json",
                    success: function (res) {
                        //console.info(data)
                        if(res.code==0){
                            toastr.success("删除成功");
                            layui.table.reload('table'); //重载表格
                            layer.close(index); //再执行关闭
                        }else{
                            layer.alert('失败:'+res.msg);
                            toastr.warning(res.msg, "异常");
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.alert('失败');
                    },
                    complete: function(XMLHttpRequest, textStatus) {
                        layer.closeAll('loading');
                    },
                });
            });
        }

        function onAllocate(item) {
            form.val('form_allocate',{id:item.id,users:item.users});

            selectUser = xmSelect.render({
                el: '#users',
                tips: '选择操作',
                filterable: true,
                direction: 'auto',
                theme: {
                    color: '#4958b9'
                },
                prop: {
                    name: 'name_ext',
                    value: 'userid',
                },
                data: users
            });

            var arr=[];
            if(item.users && item.users.length>0){
                arr = item.users.split(",");
            }
            selectUser.setValue(arr);

            layer.open({
                //area: 'auto',
                area:['400px','450px'],
                offset: '10%',
                shade: 0.5,
                shadeClose: true,
                type: 1,
                title: '分配用户', //不显示标题
                content: $('#form_allocate'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
                maxmin: false,
                btn: ['确定', '取消'],
                yes: function(index, layero){
                    //点击确认触发 iframe 内容中的按钮提交
                    lay_index=index;
                    var submit = layero.contents().find("#btn_allocate");
                    submit.click();
                }
            });
        }

        function deepCopy(obj) {
            if (typeof obj != 'object') {
                return obj;
            }
            var newobj = {};
            for (var attr in obj) {
                newobj[attr] = deepCopy(obj[attr]);
            }
            return newobj;
        }

        $(window).resize(function () {
            //console.info('resize')
            resize();
        });
        function resize() {
            var h = $('#wd_param').height();
            console.info(h)
            $(".content-scroll").slimScroll({
                height: h-70-60-50,
                size: '4px', //组件宽度
                color: '#eee', //滚动条颜色
                position: 'right', //组件位置：left/right
                distance: '0px', //组件与侧边之间的距离
                start: 'top', //默认滚动位置：top/bottom
                opacity: .4, //滚动条透明度
                alwaysVisible: true, //是否 始终显示组件
                disableFadeOut: false, //是否 鼠标经过可滚动区域时显示组件，离开时隐藏组件
                railVisible: true, //是否 显示轨道
                railColor: '#333', //轨道颜色
                railOpacity: .2, //轨道透明度
                railDraggable: true, //是否 滚动条可拖动
                railClass: 'slimScrollRail', //轨道div类名
                barClass: 'slimScrollBar', //滚动条div类名
                wrapperClass: 'slimScrollDiv', //外包div类名
                allowPageScroll: true, //是否 使用滚轮到达顶端/底端时，滚动窗口
                wheelStep: 10, //滚轮滚动量
                touchScrollStep: 200, //滚动量当用户使用手势
                borderRadius: '7px', //滚动条圆角
                railBorderRadius: '7px' //轨道圆角
            });
        }
        function formatminutes(date){
            $($(".laydate-time-list li ol")[2]).find("li").remove(); //清空秒
        }
    </script>



    <form class="layui-form" lay-filter="form_allocate" id="form_allocate" style="padding: 20px 30px 0 0;display:none;">
        <input class="layui-hide" type="text" name="id" lay-verify="">

        <div class="layui-form-item">
            <label class="layui-form-label">分配用户</label>
            <div class="layui-input-inline" style="width: 200px;">
                <div id="users" class="demo-transfer"></div>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="btn_allocate" id="btn_allocate" value="确认">
            <input type="button" lay-submit lay-filter="btn_cancel" id="btn_cancel" value="取消">
        </div>
    </form>

    <form class="layui-form" lay-filter="form_save_as" id="form_save_as" style="padding: 20px;display:none;">

        <div class="layui-form-item">
            <label class="layui-form-label layui-form-label-sm"><span class="layui-text-red">*</span> 方案名称 </label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required"  lay-verType="tips" placeholder="" autocomplete="off" class="layui-input" style="width: 100%">
            </div>
        </div>
    
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="btn_save_as" id="btn_save_as" value="确认">
        </div>
    </form>

<script src="../js/check_screen.js?v=${.Config.basic.version}"></script>

</body>
</html>